package Android.SniffDroid;

import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.PowerManager;
import android.text.ClipboardManager;

/**
 * provides a background service
 * also has to be started as one of the first components as it provides services
 * for other classes
 * @author Mike
 */
public class SniffServ extends Service {
    /** 
     * this is the object that receives interactions from clients
     */
    private final IBinder mBinder = new LocalBinder();
    /**
     * the worker thread of the service
     */
    private Thread thread;
    /**
     * the instance of the service
     */
    private static SniffServ instance = null;
    /**
     * the notification number used by this service
     */
    private int NOTIFICATION = 1;
    /**
     * the notification manager instance
     */
    private NotificationManager notMan;
    
    /**
     * Class for clients to access.  Because we know this service always
     * runs in the same process as its clients, we don't need to deal with
     * IPC.
     */
    public class LocalBinder extends Binder {
        SniffServ getService() {
            return SniffServ.this;
        }
    }
    /**
     * called when the service is created
     */    
    @Override
    public void onCreate() {
        super.onCreate();
        notMan = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        instance = this;
    }
    /**
     * returns an instance of the ClipboardManager so that other components can use it
     * @return an instance of the ClipboardManager
     */
    public static ClipboardManager getClipboardManager() {
        return (ClipboardManager)instance.getSystemService(Context.CLIPBOARD_SERVICE);
    }
    /**
     * returns an instance of the PowerManager so that other components can use it
     * @return an instance of the PowerManager 
     */
    public static PowerManager getPowerManager() {
        return (PowerManager)instance.getSystemService(Context.POWER_SERVICE);
    }
    /**
     * called when the service is started
     * @param intent the intent that started the service
     * @param flags the flags the service was started with
     * @param startId a unique identifier of this request
     * @return how the service is started, in this case this is always START_STICKY
     */
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // We want this service to continue running until it is explicitly
        // stopped, so return sticky.
        thread = new WorkerThread();
        thread.start();
        return START_STICKY;
    } 
    /**
     * called when the service is destroyed
     */
    @Override
    public void onDestroy() {
        // Tell the user we stopped.
    }
    /**
     * called when an activity binds to the service
     * @param intent the intent that was used to bind
     * @return the binder (communication object) to this service
     */
    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }
    
}